package no.group.gowther.service.dto.param;

import no.group.gowther.enums.FileType;
import no.group.gowther.exception.BusinessException;
import no.group.gowther.exception.ErrorMessage;
import org.springframework.lang.Nullable;

import java.nio.file.Files;
import java.nio.file.Path;

public class FileQueryDetailDTO {
    private Path dirPath;
    private FileType fileType;
    private Integer index;
    private String sessionId;
    private Page page;

    public FileQueryDetailDTO(Path dirPath, FileType fileType, Integer index, @Nullable String sessionId, Page page) {
        this.dirPath = dirPath;
        this.fileType = fileType;
        this.index = index;
        this.sessionId = sessionId;
        this.page = page;
        check();
    }

    private void check() {
        if (!Files.exists(dirPath)) {
            throw BusinessException.createException(ErrorMessage.PARAM_ERROR.getErrorCode(), "目录[%s]不存在".formatted(dirPath));
        }
    }

    public Path getDirPath() {
        return dirPath;
    }

    public void setDirPath(Path dirPath) {
        this.dirPath = dirPath;
    }

    public FileType getFileType() {
        return fileType;
    }

    public void setFileType(FileType fileType) {
        this.fileType = fileType;
    }

    public Integer getIndex() {
        return index;
    }

    public void setIndex(Integer index) {
        this.index = index;
    }

    public String getSessionId() {
        return sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    public Page getPage() {
        return page;
    }

    public void setPage(Page page) {
        this.page = page;
    }
}
